<template>
  <!-- 停车页面中的导航 -->
  <!-- <div class="click-home">
    <van-nav-bar
      title="停车管理"
      left-text=""
      right-text="按钮"
      @click-right="initData"
    >
      <template #right>
        <img
          class="refresh"
          src="../../assets/img/refresh.png"
          alt=""
          srcset=""
          @click="initData"
        />
      </template>
    </van-nav-bar>
  </div> -->
  <!-- 图片显示 -->
  <div class="show-img">
    <img src="../../assets/img/banner2.png" alt="" />
  </div>

  <!-- 展示消息 -->
  <div class="show-message">
    <img src="../../assets/img/mailbox.png" alt="" />
    <span class="show-message-line">|</span>
    <span class="font-control">温馨提示：目前车位已满，请选择其它地方停车！</span>
  </div>

  <!-- 流动车位剩余数 -->
  <div class="parking-main">
    <div class="parking-main_top">
      <img src="../../assets/img/icon-parking.png" alt="" srcset="" />
      <strong>流动车位剩余数</strong>
    </div>
    <div class="parking-main_content">
      <van-row v-for="(item, index) in state.park.list" :key="index">
        <van-col :span="8" class="first_local">
          <van-icon name="location-o" />
          <strong>{{ item.text }} </strong>
          <div class="local_line"></div>
        </van-col>
        <van-col :span="16" class="last_local">
          <strong
            class="text-num"
            :style="{
              color:
                item.process == '0'
                  ? 'rgb(255, 204, 51)'
                  : item.process > 30 ? 'rgb(35, 100, 184)' : 'rgb(255, 102, 0)',
            }"
          >
            {{ dealParkingNumber(item.num, item.num_use_extend) }}
          </strong>
          <span v-if="item.process > 30" class="text_local"
            >该停车场车位充足</span
          >
          <span v-else-if="item.process > 0" class="text_local"
            >该停车场车位少量</span
          >
          <span v-else class="text_local text_size"
            >该停车场位置已满，请前往{{
              state.park.hasPosition.text
            }}停车场</span
          >
          <img
            v-if="item.process > 30"
            class="show_info"
            src="../../assets/img/icon-duo.png"
            alt=""
            srcset=""
          />
          <img
            v-else-if="item.process > 0"
            class="show_info"
            src="../../assets/img/icon-shao.png"
            alt=""
            srcset=""
          />
          <img
            v-else
            class="show_info"
            src="../../assets/img/icon-man.png"
            alt=""
            srcset=""
          />
        </van-col>
      </van-row>
    </div>
  </div>
</template>

<script>
import {
  computed,
  defineComponent,
  onMounted,
  onUnmounted,
  reactive,
  ref,
} from "@vue/runtime-core";
import { GetParkCarList } from "@/api/index";
import { useStore } from "vuex";

export default defineComponent({
  name: "parking",
  setup() {
    //   变量区域
    const list = reactive([]);
    const timer = ref(null);
    const store = useStore();

    // 方法区域
    const dealParkingNumber = (num1, num2) => {
      let count = Number(num1) - Number(num2);
      return count;
    };
    const initData = () => {
      // 后台接口注释
      store.dispatch("park/GetParkCarList").then((res) => {
        // console.log("store");
      });
    };
    // 挑选出最优的停车场

    // 使用store
    const state = computed(() => {
      return store.state;
    });
    const getMaxCar = computed(() => {
      return 1;
    });
    // 获取初始化数据
    onMounted(() => {
      initData();
      // timer.value = setInterval(() => {
      //   initData();
      // }, 10000);
    });
    onUnmounted(() => {
      window.clearInterval(timer);
    });
    return {
      list,
      dealParkingNumber,
      state,
      getMaxCar,
      initData,
    };
  },
});
</script>

<style lang="less" scoped>
.click-home {
  /deep/ .van-nav-bar__left {
    display: none;
  }
  /deep/ .van-nav-bar {
    background: #2263b6;
    .van-nav-bar__title {
      color: #fff;
    }
  }
  .refresh {
    width: 40px;
    height: 40px;
  }
}
.show-img {
  // height: 514px;
  // width: 100%;
  max-width: 750px;
  img {
    width: 100%;
    object-fit: cover;
  }
}
.show-message {
  height: 90px;
  border-bottom: 1px solid #d4d4d4;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 30px;
  .show-message-line {
    // font-size: 18px;
    padding: 0 10px;
  }
  img {
    // height: 46px;
    margin-top: -4px;
    padding-left: 20px;
    width: 80px;
  }
  .font-control{
    font-size: 28px;
  }
}
.font14 {
  font-size: 14px;
}
.parking-main {
  // background: pink;
  // margin: 26px;
  border-radius: 10px;
  .parking-main_top {
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2263b6;
    margin: 40px;
    border-radius: 30px;
    img {
      width: 100px;
    }
    strong {
      font-size: 40px;
      color: #fff;
      margin-left: 30px;
    }
  }
}
.parking-main_content {
  margin: 40px;
  .van-row {
    height: 200px;
    border: 1px solid #ccc;
    background: rgb(243, 246, 255);
    margin-bottom: 60px;
    border-radius: 30px;
    .first_local {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-evenly;
      font-size: 46px;
      color: #2263b6;
      position: relative;
      .van-icon {
        color: rgb(175, 204, 241);
        font-size: 80px;
      }
    .local_line {
        width: 1px;
        height: 200px;
        background: #ccc;
        position: absolute;
        right: 0;
    }
    }
    .last_local {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-evenly;
      position: relative;
      .text_local {
        font-size: 46px;
        color: rgb(153, 153, 153);
      }
      strong {
        font-size: 90px;
      }
      .show_info {
        width: 80px;
        height: 80px;
        position: absolute;
        top: -30px;
        right: -30px;
      }
      .text_size{
        font-size: 20px;
      }
    }
  }
}
</style>
